#include"tcp_socket.hpp"

class TcpClient{
    public:
    TcpClient(std::string ip,u_int16_t port):_server_ip(ip),_server_port(port){
        _sock.Socket();
    }
    ~TcpClient(){
        _sock.Close();
    }
    bool Connect(){
        struct sockaddr_in addr;
        addr.sin_family=AF_INET;
        addr.sin_addr.s_addr=inet_addr(_server_ip.c_str());
        addr.sin_port=htons(_server_port);
        int n=connect(_sock.Getfd(),(sockaddr*)(&addr),sizeof(addr));
        if(n==-1){
            std::cerr<<"connect error\n";
            return false;
        }
        return true;
    }
    bool Recv(std::string* resp){
        _sock.Recv(resp);
        return true;
    }
    bool Send(std::string req){
        _sock.Send(req);
        return true;
    }
    private:
    TcpSocket _sock;
    std::string _server_ip;
    u_int16_t _server_port;
};